package com.example.test.Admin_function;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.test.R;
import com.example.test.all_Myhelper.exam_Myhelper;
import com.example.test.bottom_tab.tab_main_activity;
import com.example.test.exam.all_tiku;
import com.example.test.login.admin;

public class add_tiku extends AppCompatActivity implements View.OnClickListener{

    exam_Myhelper exam_myhelper;
    public EditText add_timu,A,B,C,D,da_an;
    public Button add,back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_tiku);
        exam_myhelper  = new exam_Myhelper(this);
        init();
    }
    private void init(){
        add_timu = (EditText) findViewById(R.id.add_timu);
        A = (EditText) findViewById(R.id.add_A);
        B = (EditText) findViewById(R.id.add_B);
        C = (EditText) findViewById(R.id.add_C);
        D = (EditText) findViewById(R.id.add_D);
        da_an = (EditText) findViewById(R.id.add_correct);
        add = (Button) findViewById(R.id.add_bt);
        back = (Button) findViewById(R.id.add_back);
        add.setOnClickListener(this);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent test_add = new Intent(add_tiku.this, tab_main_activity.class);
                startActivity(test_add);
            }
        });
    }

    @Override
    public void onClick(View v) {
        String title=null;
        SQLiteDatabase db;
        if(v.getId()==R.id.add_bt){
            if(add_timu.getText()==null || A.getText()==null || B.getText()==null || C.getText()==null || D.getText()==null || da_an.getText()==null){
                Toast.makeText(this,"输入的内容不能为空",Toast.LENGTH_SHORT).show();
            }
            db = exam_myhelper.getReadableDatabase();
            db.execSQL("insert into tiku (title,A,B,C,D,daan) values (?,?,?,?,?,?)",new Object[]{add_timu.getText().toString(),A.getText().toString(),B.getText().toString(),C.getText().toString(),D.getText().toString(),da_an.getText().toString()});
            Toast.makeText(this,"信息已插入",Toast.LENGTH_SHORT).show();
            db.execSQL("delete from tiku where title='' or A='' or B='' or C='' or D='' or daan=''");
            db.close();
        }
        Intent ad = new Intent(add_tiku.this, all_tiku.class);
        startActivity(ad);
    }
}